package com.example.offer.no0003.impl;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import com.example.offer.no0003.Solution;

/**
 * @author yumuhui <yumuhui@kuaishou.com>
 * Created on 2021-05-13
 */
public class SolutionImpl implements Solution {

    @Override
    public int findRepeatNumber(int[] nums) {
        if (Objects.isNull(nums) || nums.length < 2) {
            return 0;
        }

        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            if (set.contains(num)) {
                return num;
            }
            set.add(num);
        }

        return 0;
    }
}
